#light

/// File: File: RegressionTests\ViewletEvents.fs
/// 
/// Author: Antonio Cisternino (cisterni@di.unipi.it)
///   
/// ------------------------------------------------------------
/// Copyright (c) Microsoft Corporation.  All rights reserved.
/// 
/// The use and distribution terms for this software are 
/// contained in the file named license.txt, which can be found 
/// in the root of this distribution.
/// By using this software in any fashion, you are agreeing to 
/// be bound by the terms of this license.
///
/// You must not remove this notice, or any other, from this
/// software.
/// ------------------------------------------------------------

#r "ViewletControls.dll"
#r "VSLabFSICore.dll"

open System.Drawing
open VSLab

type ShowStringViewlet() =
  inherit Viewlet()
  
  [<DefaultValue>]
  val mutable displayString : string
    
  override self.OnPaint(e) =
    let g = e.Graphics
    g.DrawString(self.displayString, self.Font, Brushes.Black, 0.0f, 0.0f)

type MouseMotionViewlet() as x =
  inherit ShowStringViewlet()
    
  do x.displayString <- "Move the mouse inside the area"
  
  override self.OnMouseMove(e) =
    self.displayString <- sprintf "x: %d, y: %d - %s" (e.X) (e.Y) (System.DateTime.Now.ToString())
    self.Invalidate(new Rectangle(0, 0, 200, 50))  

  override x.OnMouseEnter (e) =
    printfn "Enter"

  override x.OnMouseLeave (e) =
    printfn "Leave"

  override x.OnMouseHover (e) =  
    x.displayString <- "Mouse hover"
    x.Invalidate()

  override x.OnInvalidated (e) =
    printfn "Invalidated"

let mmv = new MouseMotionViewlet()
mmv.Show()
mmv.Close()

type ResizeViewlet() as x =
  inherit ShowStringViewlet()
  
  do x.displayString <- "Resize the viewlet"
  
  override x.OnSizeChanged (e) =
    x.displayString <- sprintf "Size is (%d, %d)" (x.Width) (x.Height)

  override x.OnResize (e) =
    x.displayString <- "Resize changed"
    x.Invalidate()

  override x.OnClientSizeChanged (e) =
    x.displayString <- "Client Size changed"
    x.Invalidate()

let rv = new ResizeViewlet()
rv.Show()
rv.Close()

type MouseUpDownViewlet() as x =
  inherit ShowStringViewlet()
  
  do x.displayString <- "Click here"
  
  override x.OnMouseDown (e) =
    x.displayString <- "Mouse down"
    x.Invalidate()

  override x.OnMouseUp (e) =
    x.displayString <- "Mouse up"
    x.Invalidate()

  override x.OnClick e =
    printfn "Mouse click"

  override x.OnMouseClick (e) =
    printfn "Mouse click"

  override x.OnDoubleClick (e) =
    printfn "Mouse double click"
  
  override x.OnMouseDoubleClick e =
    printfn "Mouse double click"  

  override x.OnMouseWheel (e) =
    x.displayString <- "Mouse wheel"
    x.Invalidate()    

let mudv = new MouseUpDownViewlet()
mudv.Show()
mudv.Close()

type FrameEventsViewlet() as x =
  inherit ShowStringViewlet()
  
  do x.displayString <- "Click here"

  override x.OnGotFocus (e) =
    x.displayString <- "Got Focus"
    x.Invalidate()
  
  override x.OnLostFocus (e) =
    x.displayString <- "Lost focus"
    x.Invalidate()

let fev = new FrameEventsViewlet()
fev.Show()
fev.Close()

type KeyViewlet() as x =
  inherit ShowStringViewlet()
  
  do x.displayString <- "Click here"

  override x.OnKeyDown (e) =
    x.displayString <- sprintf "Pressed down %s" (e.KeyCode.ToString())
    x.Invalidate()

  override x.OnKeyUp (e) =
    x.displayString <- sprintf "Pressed up %s" (e.KeyCode.ToString())
    x.Invalidate()

  override x.OnKeyPress (e) =
    x.displayString <- sprintf "Pressed %c" (e.KeyChar)
    x.Invalidate()

  // SEEM NOT WORKING
  override x.OnPreviewKeyDown (e) =
    x.displayString <- sprintf "Preview key down %s" (e.KeyCode.ToString())
    x.Invalidate()

let kv = new KeyViewlet()
kv.Show()
kv.Close()

type DragAndDropViewlet() as x =
  inherit ShowStringViewlet()
  
  do x.displayString <- "Click here"

  // NOT SUPPORTED
  override x.OnDragDrop (e) =
    x.displayString <- "Drag and Drop event"
    x.Invalidate()

  // NOT SUPPORTED
  override x.OnDragEnter (e) =
    x.displayString <- "Drag Enter event"
    x.Invalidate()

  // NOT SUPPORTED
  override x.OnDragLeave (e) =
    x.displayString <- "Drag Leave event"
    x.Invalidate()
  
  // NOT SUPPORTED
  override x.OnDragOver (e) =
    x.displayString <- "Drag Over event"
    x.Invalidate()

  // NOT SUPPORTED
  override x.OnQueryContinueDrag (e) =
    x.displayString <- "Query Continue Drag"
    x.Invalidate()

  // NOT SUPPORTED
  override x.OnGiveFeedback (e) =
    x.displayString <- "GiveFeedback"
    x.Invalidate()

type MiscEvtViewlet() as x =
  inherit ShowStringViewlet()
  
  do x.displayString <- "Click here"
  
  override x.OnAutoSizeChanged (e) =
    x.displayString <- "AutoSize changed"
    x.Invalidate()
  
  override x.OnAutoValidateChanged (e) = 
    x.displayString <- "AutoValidate changed"
    x.Invalidate()
  
  override x.OnBackColorChanged (e) =
    x.displayString <- "BackColor changed"
    x.Invalidate()
    
  override x.OnBackgroundImageChanged (e) =
    x.displayString <- "BackgroundImage changed"
    x.Invalidate()
  
  override x.OnBackgroundImageLayoutChanged (e) =
    x.displayString <- "BackgroundImageLayout changed"
    x.Invalidate()

  // To be supported  
  override x.OnContextMenuChanged (e) =
    x.displayString <- "ContextMenu changed"
    x.Invalidate()
  
  // To be supported
  override x.OnContextMenuStripChanged (e) =
    x.displayString <- "ContextMenuStrip changed"
    x.Invalidate()

  // To be supported
  override x.OnCursorChanged (e) =
    x.displayString <- "Cursor changed"
    x.Invalidate()
    
  override x.OnEnabledChanged (e) =
    x.displayString <- "Enabled changed"
    x.Invalidate()
  
  override x.OnFontChanged (e) =
    x.displayString <- "Font changed"
    x.Invalidate()

  override x.OnForeColorChanged (e) =
    x.displayString <- "ForeColorChanged changed"
    x.Invalidate()
  
  // To be supported
  override x.OnImeModeChanged (e) =
    x.displayString <- "ImeMode changed"
    x.Invalidate()
  
  // To be supported
  override x.OnLoad (e) =
    x.displayString <- "Load event"
    x.Invalidate()

  // To be supported  
  override x.OnMouseCaptureChanged (e) =
    x.displayString <- "MouseCapture changed"
    x.Invalidate()

  override x.OnRightToLeftChanged (e) = 
    x.displayString <- "RightToLeft changed"
    x.Invalidate()
  
  override x.OnSystemColorsChanged (e) =
    x.displayString <- "SystemColors changed"
    x.Invalidate()
    
  override x.OnTextChanged (e) =
    x.displayString <- "Text changed"
    x.Invalidate()
  
  override x.OnVisibleChanged (e) =
    printfn "Visibility change"

let mev = new MiscEvtViewlet()
mev.Show()
mev.ShowProperty()
mev.Cursor <- System.Windows.Forms.Cursors.Cross
mev.Close()
